<?php

namespace App\Http\Controllers\Admin;

use App\Coupon;
use App\Http\Controllers\Controller;
use App\Http\Response;
use App\UserCoupon;
use Carbon\Carbon;
use Illuminate\Http\Request;

class UserCouponController extends Controller
{
    use Response;
    public function store(Request $request)
    {
        $uid=$request->get('user_id');
        $coupon_id=$request->get('coupon_id');
        $number=$request->get('number');
        $coupon=Coupon::find($coupon_id);
        for($i=0;$i<$number;$i++){
            $user_coupon=[
                'uid'=>$uid,
                "coupon_id"=>$coupon->id,
                "price"=>$coupon->price,
                "fill_money"=>$coupon->fill_money,
                "exp_time"=>Carbon::now()->addDays($coupon->exp_day),
                "status"=>0,
                "bind_goods"=>[],
                "title"=>$coupon->title
            ];
            UserCoupon::create($user_coupon);
        }

        return $this->message(200,"优惠券发放成功");
    }
}
